plugins["Mute"] = "kontrol_mute"

if SERVER then
	function Mute(pl, cmd, args)
		if !pl:KAdmin() && !pl:KModerator() then return end
		
		local muteToggle = tobool(args[2])
		local target = player.GetByUniqueID(args[1])
		local admin = pl
		
		if ValidEntity(target) then
			for k,v in pairs(player.GetAll()) do
				v:SendLua("player.GetByUniqueID('" .. args[1] .. "'):SetMuted(" .. tostring(muteToggle) .. ")")
			end
		end
	end
	concommand.Add("sv_kontrol_mute", Mute)
end

if CLIENT then
	function MuteMenu(pl, cmd, args)
		local id = args[1]
	
		local menu = vgui.Create("KFrame2")
		menu:SetSize(120, 92)
		menu:SetPos(ScrW() / 2 - 60, ScrH() / 2 - 46)
		menu:SetTitle("Mute Options")
		menu:SetDraggable(true)
		menu:ShowCloseButton(true)
		menu:SetSizable(false)
		menu:MakePopup()
		
		local mute = vgui.Create("KButton", menu)
		mute:SetSize(100, 20)
		mute:SetPos(10, 32)
		mute:SetText("Mute")
		mute.DoClick = function()
			RunConsoleCommand("sv_kontrol_mute", id, "1")
		end
		
		local unmute = vgui.Create("KButton", menu)
		unmute:SetSize(100, 20)
		unmute:SetPos(10, 62)
		unmute:SetText("Unmute")
		unmute.DoClick = function()
			RunConsoleCommand("sv_kontrol_mute", id, "0")
		end
	end
	concommand.Add("kontrol_mute", MuteMenu)
end